// @flow
import React, { Component } from 'react'
import { Button, Form, Modal, Select, Row, Col, Collapse } from 'antd'
// import ProblemLi from 'components/ProblemLi'
import ProblemLi from './ProblemList'
const Panel = Collapse.Panel
type Props = {
  data: Object
}
type States = {
  visible: boolean,
  fields1: Object,
  fields2: Object,
  fields3: Object,
  fields4: Object
}
class LinkToDetail extends Component {
  props: Props
  state: States
  goToLink: Function
  closeCondition: Function
  constructor (props: Props) {
    super(props)
    this.state = {
      visible: false,
      fields1: {},
      fields2: {},
      fields3: {},
      fields4: {}
    }
    this.goToLink = this.goToLink.bind(this)
    this.closeCondition = this.closeCondition.bind(this)
  }

  goToLink () {
    const { data } = this.props
    this.setState({
      visible: true,
      fields1 : {
        '振动分类': data.faultCategories,
        '振动故障直接原因': data.directCause,
        '振动原因分类': data.reasonCategories,
        '特征': data.characteristics
      },
      fields2 : {
        '振动主导频率': data.vibrationDominantFrequency,
        '常伴频率': data.withFrequency,
        '振动稳定性': data.vibrationStability,
        '相位特征': data.phaseCharacteristics,
        '振动方向': data.vibrationDirection,
        '转子轨迹': data.rotorTrajectory,
        '振动随转速变化': data.vibrationSpeedChange,
        '振动随油温变化': data.vibrationLoadChange,
        '振动随负荷变化': data.vibrationOilChange,
        '振动随出口压力变化': data.vibrationPressureChange,
        '与类似振动故障判别方法': data.vibrationMethod
      },
      fields3 : {
        '设计制造': data.designManufacture,
        '安装维修': data.installation,
        '运行操作': data.operation,
        '机器劣化': data.machineDeterioration
      },
      fields4 : {
        '防治方法': data.preventionMethod
      }
    })
  }
  closeCondition () {
    this.setState({
      visible: false
    })
  }
  render () {
    const { directCause } = this.props.data
    const { fields1, fields2, fields3, fields4 } = this.state
    return (
      <div>
        <a onClick={this.goToLink}>
          {directCause}
        </a>
        <Modal
          title='详细信息'
          width={800}
          visible={this.state.visible}
          onCancel={this.closeCondition}
          footer={null}
          >
          <div style={{ height:455, overflow: 'auto' }}>
            <ProblemLi title='振动故障机理' data={fields1} />
            <ProblemLi title='振动故障识别特征' data={fields2} />
            <ProblemLi title='振动二次原因' data={fields3} />
            <ProblemLi title='防治方法' data={fields4} />
          </div>
        </Modal>
      </div>
    )
  }
}

export default LinkToDetail
